package jp.shuitic.hatebwebhook.twitter.web.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
/**
 * ログインをチェックして入力画面を表示する
 * @author shuitic
 */
@SuppressWarnings("serial")
public class HatebWebHookTwitInputServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
		UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();
        if (user != null) {
        	String logoutUrl = userService.createLogoutURL("/");
            req.setAttribute("logoutUrl", logoutUrl);
            String nickname = user.getNickname();
            req.setAttribute("nickname", nickname);
            req.getRequestDispatcher("/WEB-INF/jsp/HatebWebHookTwit.jsp").forward(req, resp);
        } else {
            resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
        }
	}
}
